package com.ciban.smarthome.module.db.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.ciban.smarthome.module.db.DbBaseDao;
import com.ciban.smarthome.module.entity.Equip_Curtain;
import com.ciban.smarthome.module.entity.Equip_Projector;

import java.util.ArrayList;

/**
 * Created by wdl on 2015/11/10.
 */
public class ProjectorDao extends DbBaseDao {
    /*projector(_id integer, scene_id integer default -1,status integer)*/
    public ProjectorDao(Context context) {
        super(context, "projector");
    }

    /**
     * 添加新的投影仪
     * @param info
     * @return
     */
    public long addNewProjector(Equip_Projector info){
        ContentValues values=new ContentValues();
        values.put("_id", info.getId());
        values.put("scene_id", info.getScene_id());
        values.put("status", info.getStatus());
        values.put("screen_serialno", info.getPro_screen_serialno());

        return insert(null, values);
    }

    /**
     * 更新投影仪配置信息
     * @param info
     * @return
     */
    public int updateProjector(Equip_Projector info){
        ContentValues values=new ContentValues();
        values.put("_id", info.getId());
        values.put("scene_id", info.getScene_id());
        values.put("status", info.getStatus());
        values.put("screen_serialno", info.getPro_screen_serialno());

        return update(values, "_id=?", new String[]{info.getId()});
    }

    /**
     * 删除投影仪
     * @param id
     * @return
     */
    public int delProjector(String id){
        return del("_id=?", new String[]{id});
    }

    /**
     * 联表获取投影仪的信息
     * @param area_id
     * @param type
     */
    public ArrayList<Equip_Projector> getProjectorList(String area_id, int type){
        ArrayList<Equip_Projector> list = new ArrayList<Equip_Projector>();
        String sql = "select  e.[_id],e.[area_id],e.[icon],e.[name],e.[serial_num],e.[type],l.[scene_id],l.[status],l.[screen_serialno]   from equipment e,projector l where e.[type]=? and e.[area_id]=? and l.[scene_id]=-1 and e.[_id]=l.[_id] ";
        Cursor cursor = execRawQuery(sql, new String[]{type + "", area_id});
        if (cursor != null) {
            Equip_Projector info;
            while (cursor.moveToNext()) {
                info = new Equip_Projector();
                info.setId(cursor.getString(0));
                info.setArea_id(cursor.getString(1));
                info.setIcon_path(cursor.getString(2));
                info.setName(cursor.getString(3));
                info.setSerial_no(cursor.getInt(4));
                info.setType(cursor.getInt(5));
                info.setScene_id(cursor.getString(6));
                info.setStatus(cursor.getInt(7));
                info.setPro_screen_serialno(cursor.getInt(8));

                list.add(info);
            }
        }
        return list;
    }


}
